package com.sangmo.fts.process.inventory.model;

import com.sangmo.boot.framework.data.entity.general.SoftDeleteEntity;
import com.sangmo.boot.framework.data.json.meta.ExtView;
import com.sangmo.boot.framework.data.json.meta.Formula;
import com.sangmo.boot.framework.data.json.meta.Many;
import com.sangmo.boot.framework.data.json.meta.One;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataField;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataView;
import com.sangmo.fts.basic.model.Company;
import com.sangmo.fts.common.IConstants;
import com.sangmo.fts.process.inventory.service.IfWaybillService;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;

import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.util.Date;

@Entity
@Table(name = "if_waybill")
@DataView
@ExtView
//@Formula()
@SQLDelete(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@SQLDeleteAll(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@Where(
        clause = "deleted = 0"
)
public class IfWaybill extends SoftDeleteEntity {

    @Many(src = "id", value = "waybillItems", target = IfWaybillItem.class, ref = "waybillId", groups = {"IfWaybill.detail"})

    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long trainingId;

    @DataField(value = IConstants.DATA_TYPE.STRING_50,required = true, index = true, unique = true)
    private String code;

    @One(value = "contract", target = IfContract.class, fieldset = {"id", "code"}, groups = {"IfWaybill.search","IfWaybill.detail"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long contractId;

    @One(value = "shipperCompany", target = Company.class, fieldset = {"id", "name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true)
    private Long shipper;

    @One(value = "consigneeCompany", target = Company.class, fieldset = {"id", "name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true)
    private Long consignee;

    @DataField(value = IConstants.DATA_TYPE.DATE, required = true)
    private Date shippingTime;

    @DataField(value = IConstants.DATA_TYPE.STRING_10, required = true)
    private String originPlace;

    private Date receiptTime;

    private String receiptPlace;

    @DataField(value = IConstants.IF_WAYBILL_DATA_TYPE.WAYBILL_STATE, required = true, index = true)
    private String state = States.PENDING;

    public Long getTrainingId() {
        return trainingId;
    }

    public void setTrainingId(Long trainingId) {
        this.trainingId = trainingId;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Long getContractId() {
        return contractId;
    }

    public void setContractId(Long contractId) {
        this.contractId = contractId;
    }

    public Long getShipper() {
        return shipper;
    }

    public void setShipper(Long shipper) {
        this.shipper = shipper;
    }

    public Long getConsignee() {
        return consignee;
    }

    public void setConsignee(Long consignee) {
        this.consignee = consignee;
    }

    public Date getShippingTime() {
        return shippingTime;
    }

    public void setShippingTime(Date shippingTime) {
        this.shippingTime = shippingTime;
    }

    public String getOriginPlace() {
        return originPlace;
    }

    public void setOriginPlace(String originPlace) {
        this.originPlace = originPlace;
    }

    public Date getReceiptTime() {
        return receiptTime;
    }

    public void setReceiptTime(Date receiptTime) {
        this.receiptTime = receiptTime;
    }

    public String getReceiptPlace() {
        return receiptPlace;
    }

    public void setReceiptPlace(String receiptPlace) {
        this.receiptPlace = receiptPlace;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    /*public interface ShipStates{
        String PENDING = "PENDING"; //待发货
        String SHIPPED = "SHIPPED"; //已发货
    }

    public interface ReceiveStates {
        String DISPATCHED = "DISPATCHED"; //待接收
        String RECEIVED = "RECEIVED"; //已接收
    }*/

    public interface States {
        String PENDING = "PENDING"; //待发货
        String DISPATCHED = "DISPATCHED"; //待接收
        String RECEIVED = "RECEIVED"; //已接收
    }
}
